
import * as api from './service'
const Model = {
  namespace: 'worker',
  state: {
    workerInfo: {}, // 员工
  },
  effects: {
    // *changePwd({ payload }, { call, put}) {
    //   const res = yield call(api.changePwd, payload)
    //   return new Promise((resolve, reject) => {
    //     if(res) {
    //       resolve(res)
    //     } else {
    //       reject()
    //     }
    //   })
    // },
    *getWorkerInfo({ payload }, { call, put }) {
      const res = yield call(api.getWorkerInfo, payload)
      if(res) {
        yield put({
          type: 'save',
          payload: {
            key: 'workerInfo',
            data: res.data
          }
        })
      }
    },
    // 获取员工 工时记录
    *getWorkerRecordList({payload}, { call, put}) {
      const res = yield call(api.getWorkerRecordList, payload)
      return new Promise((resolve, reject) => {
        if(res) {
          resolve(res)
        } else {
          reject()
        }
      })
    },
    // 
    // 获取员工 工资支付列表
    *getPayList({payload}, { call, put}) {
      const res = yield call(api.getPayList, payload)
      return new Promise((resolve, reject) => {
        if(res) {
          resolve(res)
        } else {
          reject()
        }
      })
    },
    // 获取员工 日统计
    *getDayStatistics({payload}, { call, put}) {
      const res = yield call(api.getDayStatistics, payload)
      return new Promise((resolve, reject) => {
        if(res) {
          resolve(res)
        } else {
          reject()
        }
      })
    },
    //  用户工时月统计列表获取 getMonthStatistics
    *getMonthStatistics({payload}, { call, put}) {
      const res = yield call(api.getMonthStatistics, payload)
      return new Promise((resolve, reject) => {
        if(res) {
          resolve(res)
        } else {
          reject()
        }
      })
    },
  },
  reducers: {
    save(state, action) {
      return{...state, [action.payload.key]: action.payload.data}
    }
  }
}
export default Model